<template>
  <div class="index">
    <div class="left">
      <h2>高校信息平台</h2>
      <el-menu
        default-active="2"
        background-color="#369"
        text-color="#fff"
        active-text-color="#ffd04b">
        <el-submenu index="1">
          <template slot="title">
            <i class="el-icon-user"></i>
            <span>用户管理</span>
          </template>
          <el-menu-item index="1-1" @click="goto('/user')">用户信息</el-menu-item>
          <el-menu-item index="1-2">登录记录</el-menu-item>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-s-custom"></i>
            <span>学生管理</span>
          </template>
          <el-menu-item index="2-1">学生信息</el-menu-item>
          <el-menu-item index="2-2">学籍信息</el-menu-item>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title">
            <i class="el-icon-s-platform"></i>
            <span>教学管理</span>
          </template>
          <el-menu-item index="3-1">课程信息</el-menu-item>
          <el-menu-item index="3-2">成绩信息</el-menu-item>
        </el-submenu>
      </el-menu>
    </div>
    <div class="right">
      <div class="top">
        <el-menu
          default-active="1"
          mode="horizontal"
          background-color="#369"
          text-color="#fff"
          active-text-color="#ffd04b">
          <el-menu-item index="1"><i class="el-icon-s-home"></i>首页</el-menu-item>
          <el-menu-item index="2"><i class="el-icon-s-comment"></i>消息</el-menu-item>
          <el-menu-item index="3"><i class="el-icon-message"></i>邮件</el-menu-item>
          <el-submenu index="4">
            <template slot="title"><i class="el-icon-s-custom"></i>管理员</template>
            <el-menu-item index="4-1">个人中心</el-menu-item>
            <el-menu-item index="4-2">修改密码</el-menu-item>
            <el-menu-item index="4-3" @click="exit">退出系统</el-menu-item>
          </el-submenu>
        </el-menu>
      </div>
      <div class="content">
        <!-- 二级路由出口 -->
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    goto(path){
      if(this.$route.path!=path){
        this.$router.push(path)
      }
    },
    exit(){
      this.$confirm('确定退出系统吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          sessionStorage.clear()  //清除缓存
          this.$router.push('/')  //跳转到登录页
        }).catch(() => {});
    }
  },
  mounted(){
    if(!sessionStorage.getItem('user')){
      this.$message({
        message:'请先登录系统',
        type:'warning'
      })
      this.$router.push('/')
    }
  }
};
</script>

<style lang="scss" scoped>
.index {
  width: 100vw;
  height: 100vh;
  display: flex;
  .left {
    width: 200px;
    background-color: #369;
    h2 {
      text-align: center;
      line-height: 60px;
      color: white;
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    .top {
      height: 60px;
      background-color: #369;
      display: flex;
      justify-content: flex-end;
    }
    .content {
      flex: 1;
      padding: 10px;
    }
  }
}
</style>
